package com.jaydenxiao.common.baseapp;

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

import io.reactivex.annotations.Nullable;
import okhttp3.ResponseBody;
import retrofit2.Converter;
import retrofit2.Retrofit;

/**
 * Created by hasee on 2017/10/11.
 */

public class StringConverterFactory extends Converter.Factory {

    public static final StringConverterFactory INSTANCE=new StringConverterFactory();

    public static StringConverterFactory creat(){
        return INSTANCE;
    }

    @Nullable
    @Override
    public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
        if (type==String.class){
            return StringConverter.INSTANCE;
        }
        return null;
    }

    public static class StringConverter implements Converter<ResponseBody, String> {
        public static final StringConverter INSTANCE = new StringConverter();
        @Override
        public String convert(ResponseBody value) throws IOException {
            return value.string();
        }
    }

}
